package appapi.dao;

import appapi.entity.mqtt.Devices;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @version: java version 1.8
 * @Author: Ygp Work
 * @description:
 * @date: 2023-07-05 10:29
 */
@Mapper
public interface DevicesMapper {
    @Insert("INSERT INTO devices (equipment_number, address, version_information, now_time,equipment_type) " +
            "VALUES ( #{equipmentNumber}, #{address}, #{versionInformation}, #{nowTime},#{equipmentType})")
    void insertDevices(Devices devices);

    @Update("UPDATE devices SET equipment_number = #{equipmentNumber}, address = #{address}, " +
            "version_information = #{versionInformation}, now_time = #{nowTime} WHERE devices_id = #{devicesId}")
    void updateDevices(Devices devices);

    @Delete("DELETE FROM devices WHERE devices_id = #{devicesId}")
    void deleteDevices(Long devicesId);

    @Select("SELECT equipment_number,address,version_information,now_time FROM devices WHERE devices_id = #{devicesId}")
    Devices getDevicesById(Long devicesId);
    @Select({"<script>",
            "SELECT equipment_number, devices_id,address, version_information, now_time,companydata,projectdata ",
            "FROM devices",
            "<if test='equipmentNumber != null'>",
            "WHERE equipment_number LIKE CONCAT('%', #{equipmentNumber}, '%')",
            "</if>",
            "</script>"})
    List<Devices> getAll(Devices devices);

    @Delete("DELETE FROM devices WHERE devices_id = #{devicesId} AND address = #{address}")
    void deleteDeviceByRegion( Long devicesId,  String address);
}
